package com.ninogame.state;

import java.io.IOException;
import java.util.ArrayList;

import org.xmlpull.v1.XmlPullParserException;

import com.ninogame.BitmapFont;
import com.ninogame.GameLayer;
import com.ninogame.GameLib;
import com.ninogame.IConstant;
import com.ninogame.MazeEscape;
import com.ninogame.Map;
import com.ninogame.Actor.Creature;
import com.ninogame.Actor.Explorer;
import com.ninogame.resolution.DEF;


import android.R.color;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.view.KeyEvent;


public class StateOption extends MazeEscape implements IConstant
{
	//
	
	public static int MENU_ELEMENT_W = 206;
	public static int MENU_ELEMENT_H = 54;
	public static int MENU_ELEMENT_SPACE = 15;

	public static RectF rectF = null;

	public static synchronized void SendMessage(int type)
	{
	
		switch (type)
		{
		case MESSAGE_CTOR:
			rectF = new RectF(DEF.CREADIT_BACKGROUND_X, DEF.CREADIT_BACKGROUND_Y, DEF.CREADIT_BACKGROUND_X + DEF.CREADIT_BACKGROUND_W, DEF.CREADIT_BACKGROUND_Y + DEF.CREADIT_BACKGROUND_H);

			break;
		case MESSAGE_UPDATE:
			if (MazeEscape.isTouchReleaseInRect(DEF.CREADIT_BACKGROUND_X + DEF.CREADIT_BACKGROUND_W - DEF.CREADIT_BUTTON_W - 8, DEF.CREADIT_BACKGROUND_Y + 8, DEF.CREADIT_BUTTON_W, DEF.CREADIT_BUTTON_H))
				if (StateGameplay.isIngame)
					changeState(STATE_IGM, true, true);
				else
					changeState(STATE_MAINMENU, true, true);

			break;
		case MESSAGE_PAINT:

			if (!StateGameplay.isIngame) {
				MazeEscape.mainPaint.setColor(Color.BLACK);
				MazeEscape.mainPaint.setStyle(Style.FILL);
				mainCanvas.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, MazeEscape.mainPaint);
				matrix.reset();
				matrix.setScale(SCREEN_WIDTH * 1f / 800, SCREEN_HEIGHT * 1f / 1280);
				mainCanvas.drawBitmap(StateMainMenu.splashBitmap, matrix, mainPaint);
			} else {
				StateGameplay.SendMessage(MESSAGE_PAINT);		
			}
			MazeEscape.mainPaint.setStyle(Style.FILL);
			MazeEscape.mainPaint.setARGB(200, 0, 0, 0);
			MazeEscape.mainCanvas.drawRect(0, 0, MazeEscape.SCREEN_WIDTH, MazeEscape.SCREEN_HEIGHT, MazeEscape.mainPaint);
			MazeEscape.mainPaint.setStyle(Style.FILL_AND_STROKE);
			MazeEscape.mainPaint.setColor(Color.rgb(67, 120, 167));
			MazeEscape.mainCanvas.drawRoundRect(rectF, 25, 25, MazeEscape.mainPaint);//CREADIT_TITLE_CONTENT_SPACE_H
			//draw text
			fontbig_Yellow.drawString(MazeEscape.mainCanvas, "OPTION", DEF.OPTION_TITLE_X, DEF.OPTION_TITLE_Y, BitmapFont.ALIGN_CENTER);
			
			//sound
			fontbig_Yellow.drawString(MazeEscape.mainCanvas, "Sound : ", DEF.OPTION_CONTENT_X - 200, DEF.OPTION_CONTENT_Y + (MENU_ELEMENT_H + MENU_ELEMENT_SPACE) + 3, BitmapFont.ALIGN_LEFT);
			if (isTouchDrapInRect(DEF.OPTION_CONTENT_X - MENU_ELEMENT_W / 2, DEF.OPTION_CONTENT_Y +  (MENU_ELEMENT_H + MENU_ELEMENT_SPACE), MENU_ELEMENT_W, MENU_ELEMENT_H))
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_BUTTON_HIGHTLIGHT, DEF.OPTION_CONTENT_X, DEF.OPTION_CONTENT_Y + MENU_ELEMENT_H / 2 +  (MENU_ELEMENT_H + MENU_ELEMENT_SPACE));
			else
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_BUTTON_NORMAL, DEF.OPTION_CONTENT_X, DEF.OPTION_CONTENT_Y  + MENU_ELEMENT_H / 2 + (MENU_ELEMENT_H + MENU_ELEMENT_SPACE));
			MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "ON", DEF.OPTION_CONTENT_X, DEF.OPTION_CONTENT_Y + (MENU_ELEMENT_H + MENU_ELEMENT_SPACE) + 3, BitmapFont.ALIGN_CENTER);
			//speed
			fontbig_Yellow.drawString(MazeEscape.mainCanvas, "Speed : ", DEF.OPTION_CONTENT_X - 200, DEF.OPTION_CONTENT_Y + 2*(MENU_ELEMENT_H + MENU_ELEMENT_SPACE) + 3, BitmapFont.ALIGN_LEFT);
			if (isTouchDrapInRect(DEF.OPTION_CONTENT_X - MENU_ELEMENT_W / 2, DEF.OPTION_CONTENT_Y +  2*(MENU_ELEMENT_H + MENU_ELEMENT_SPACE), MENU_ELEMENT_W, MENU_ELEMENT_H))
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_BUTTON_HIGHTLIGHT, DEF.OPTION_CONTENT_X, DEF.OPTION_CONTENT_Y + MENU_ELEMENT_H / 2 +  2*(MENU_ELEMENT_H + MENU_ELEMENT_SPACE));
			else
				StateGameplay.spriteDPad.drawAFrame(mainCanvas, DEF.FRAME_BUTTON_NORMAL, DEF.OPTION_CONTENT_X, DEF.OPTION_CONTENT_Y  + MENU_ELEMENT_H / 2 + 2*(MENU_ELEMENT_H + MENU_ELEMENT_SPACE));
			MazeEscape.fontbig_Yellow.drawString(MazeEscape.mainCanvas, "SLOW", DEF.OPTION_CONTENT_X, DEF.OPTION_CONTENT_Y + 2*(MENU_ELEMENT_H + MENU_ELEMENT_SPACE) + 3, BitmapFont.ALIGN_CENTER);
			
			if (MazeEscape.isTouchDrapInRect(DEF.CREADIT_BACKGROUND_X + DEF.CREADIT_BACKGROUND_W - DEF.CREADIT_BUTTON_W - 8, DEF.CREADIT_BACKGROUND_Y + 8, DEF.CREADIT_BUTTON_W, DEF.CREADIT_BUTTON_H))
				StateGameplay.spriteDPad.drawAFrame(MazeEscape.mainCanvas, DEF.FRAME_CANCEL_HIGHTLIGHT, DEF.CREADIT_BACKGROUND_X + DEF.CREADIT_BACKGROUND_W - DEF.CREADIT_BUTTON_W / 2 - 8, DEF.CREADIT_BACKGROUND_Y + DEF.CREADIT_BUTTON_H / 2 + 8);
			else
				StateGameplay.spriteDPad.drawAFrame(MazeEscape.mainCanvas, DEF.FRAME_CANCEL_NORMAL, DEF.CREADIT_BACKGROUND_X + DEF.CREADIT_BACKGROUND_W - DEF.CREADIT_BUTTON_W / 2 - 8, DEF.CREADIT_BACKGROUND_Y + DEF.CREADIT_BUTTON_H / 2 + 8);

			break;
		case MESSAGE_DTOR:
			break;
		}
	}
}
